﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Logging;
using Newtonsoft.Json.Linq;

namespace yongGu.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class StockResultController
    {
        [HttpPost]
        public ResponseFromWms2<string> Set(dynamic data)
        {
            ResponseFromWms2<string> result = new ResponseFromWms2<string>();
            DataAccess dataAccess = new DataAccess();
            Config.JsonLogger.Debug($"收到WMS执行的反馈：" + data.ToString());
            foreach (var item in data.Body)
            {
                string billNo = item?.orderNo;
                string skuCode = item?.skuCode.ToString();
                int skuQty = item.skuQty;
                string ksBinCode = item?.ksBinCode.ToString();
                if ((int)item?.orderType == 0) //0=入库1==出库
                {
                    string _statusMsg = "实际入库" + skuQty + "到料箱" + ksBinCode;
                    //string _statusMsg = "1.ok";
                    dataAccess.SetInInfo(billNo, skuCode, _statusMsg);
                }
                if ((int)item?.orderType == 1)
                {
                    string _statusMsg = "实际从料箱出库" + skuQty  + ksBinCode;
                    //string _statusMsg = "1.ok";
                    dataAccess.SetOutInfo(billNo, skuCode, _statusMsg);
                }
            }
            result.RetData = "成功";
            return result;
        }
    }
}
